local xiongguang = fk.CreateSkill{
    name = "lingling__xiongguang",
}
Fk:loadTranslationTable{
    ["lingling__xiongguang"] = "雄光",
    [":lingling__xiongguang"] = "当你于摸牌阶段外获得牌后，你可以明置之使之不计入手牌上限。每回合限两次，你可以将两张明置牌当【万箭齐发】或【无中生有】使用。",
    ["#lingling__xiongguang-invoke"] = "雄光：是否明置这些牌（%arg）",
    ["@@lingling__xiongguang-inhand"] = "雄光",
}

local DIY = require "packages/diy_utility/diy_utility"

xiongguang:addEffect(fk.AfterCardsMove, {
    anim_type = "special",
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(xiongguang.name) then
            local cards = {}
            for _, move in ipairs(data) do
                if move.to and move.to == player and move.toArea == Player.Hand and player.phase ~= Player.Draw then
                    for _, info in ipairs(move.moveInfo) do
                        if table.contains(player:getCardIds("h"), info.cardId) and not table.contains(DIY.getShownCards(player), info.cardId) then
                            table.insertIfNeed(cards, info.cardId)
                        end
                    end
                end
            end
            event:setCostData(self,{cards = cards})
            return #cards > 0
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if room:askToSkillInvoke(player, {
            skill_name = xiongguang.name,
            prompt = "#lingling__xiongguang-invoke:::"..table.concat(table.map(event:getCostData(self).cards,function (cardID)
                return Fk:getCardById(cardID):toLogString()
            end),"、"),
        }) then
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = event:getCostData(self).cards
        if cards and #cards > 0 then
            DIY.showCards(player,cards)
            for _, cardID in ipairs(cards) do
                room:setCardMark(Fk:getCardById(cardID),"@@lingling__xiongguang-inhand",1)
            end
        end
    end,
})

xiongguang:addEffect("maxcards", {
    exclude_from = function(self, player, card)
        return player:hasSkill(xiongguang.name) and card:getMark("@@lingling__xiongguang-inhand") > 0
    end,
})

xiongguang:addEffect("viewas",{
    pattern = "archery_attack,ex_nihilo",
    max_turn_use_time = 2,
    handly_pile = false,
    interaction = function(self, player)
        local all_names = {"archery_attack","ex_nihilo"}
        local names = player:getViewAsCardNames(xiongguang.name, all_names)
        if #names > 0 then
            return UI.CardNameBox { choices = names, all_choices = all_names }
        end
    end,
    card_filter = function(self, player, to_select, selected)
        return #selected < 2 and table.contains(DIY.getShownCards(player), to_select)
    end,
    view_as = function(self, player, cards)
        if #cards ~= 2 or self.interaction.data == nil then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = xiongguang.name
        card:addSubcards(cards)
        return card
    end,
    enabled_at_play = function(self, player)
        return #DIY.getShownCards(player) > 0 and self:withinTimesLimit(player,Player.HistoryTurn)
    end,
    enabled_at_response = function(self, player, cardResponsing)
        return not cardResponsing and #DIY.getShownCards(player) > 0 and self:withinTimesLimit(player,Player.HistoryTurn)
  end,
})

return xiongguang